import { ESCesiumViewer } from "@czmSrc/ESCesiumViewer";
import { MultiPointsAppendEditing } from ".";
import { ESJVector3D } from "earthsdk3";
import { extendClassProps, ReactivePropsToNativePropsAndChanged, reactPositionsSet, track } from "xbsj-base";
import { CzmPolylines } from "@czmSrc/CzmObjects";

export class VisibilityAppendEditing extends MultiPointsAppendEditing {
    constructor(czmViewer: ESCesiumViewer) {
        super(czmViewer);
        if (!czmViewer.viewer)
            this.loop = false;
        {
            const update = () => {
                if (!this.positions || this.positions.length < 2) {
                    this.visibilityPositions = undefined;
                    return;
                };
                const origin = [...this.positions[0]] as ESJVector3D;
                origin[2] -= czmViewer.editingHeightOffset ?? 0;
                this.visibilityPositions = this.positions.map(item => {
                    item[2] -= czmViewer.editingHeightOffset ?? 0;
                    return [origin, item];
                })
            }
            update();
            this.ad(this.positionsChanged.don(update));
        }
    }
    public override createPolyline(czmViewer: ESCesiumViewer) {
        const polyline = this.ad(new CzmPolylines(czmViewer));
        polyline.topOrBottom = 'bottom';
        this.ad(track([polyline, 'color'], [this, 'polylineColor']))
        this.ad(track([polyline, 'width'], [this, 'polylineWidth']))
        this.ad(track([polyline, 'show'], [this, 'polylineShow']))
        this.ad(track([polyline, 'arcType'], [this, 'polylineArcType']))
        this.ad(track([polyline, 'loop'], [this, 'loop']));
        this.ad(track([polyline, 'positions'], [this, 'visibilityPositions']));
    }
}
export namespace VisibilityAppendEditing {
    export const createDefaultProps = () => ({
        ...MultiPointsAppendEditing.createDefaultProps(),
        visibilityPositions: reactPositionsSet(undefined),
    })
}
extendClassProps(VisibilityAppendEditing.prototype, VisibilityAppendEditing.createDefaultProps);
export interface VisibilityAppendEditing extends ReactivePropsToNativePropsAndChanged<ReturnType<typeof VisibilityAppendEditing.createDefaultProps>> { }
